/**
 * Created by Administrator on 16-2-26.
 */


function cook(){
    // cook页面导航栏点击下拉浮动层
    var time = null;
    var header_c = $('.header .c'), header_r = $('.header .r');
    var back = $('.cook_dialog_back');
    var dialog = $('.cook_dialog'), filter_li = dialog.find('.filter li'),
        range_li = dialog.find(('.range li'));
    header_c.on('touchend',function(e){
        e.stopPropagation();
//        if(!time)  clearTimeout(time);
        if($(this).hasClass('on')){
            $(this).removeClass('on');
            dialog.removeClass('fadedown').addClass('fadeup');
            time = setTimeout(function(){
                if(time){
                    clearTimeout(time);
                    time = null;
                }
                back.removeClass('on1');
            },300);
        }else{
            $(this).addClass('on');
            dialog.removeClass('fadeup').addClass('fadedown');
            time = setTimeout(function(){
                if(time){
                    clearTimeout(time);
                    time = null;
                }
            },300);
            back.addClass('on1');
        }
    });
    header_r.on('touchend',function(e){
        e.stopPropagation();
        if(back.hasClass('on1')){
        }else{
            if(back.css('display') == 'none'){
                back.addClass('on2');
            }else{
                back.removeClass('on2');
            }
        }

    });
    back.on('touchend',function(e){
        if(e.target == this){
//            back.removeClass('on1 on2');
            if(header_c.hasClass('on')){
                header_c.removeClass('on');
                dialog.removeClass('fadedown').addClass('fadeup');
                time = setTimeout(function(){
                    if(time){
                        clearTimeout(time);
                        time = null;
                    }
                    back.removeClass('on1');
                },300);
            }
            if(back.hasClass('on2')){
                back.removeClass('on2')
            }
        }


    });
    filter_li.on('touchend',function(e){
        e.stopPropagation();
       $(this).addClass('on').siblings().removeClass('on');
    });
    range_li.on('touchend',function(e){
        e.stopPropagation();
        $(this).addClass('on').siblings().removeClass('on');
    })
}
cook();

function dialog(showel,backel,closeel){
    var show = $(showel);
    var back = $(backel), close = back.find(closeel);
    show.on('touchend',function(){
        back.fadeIn(300);
    });
    close.on('touchend',function(){
        back.fadeOut(300);
    });
    back.on('touchend',function(e){
        if(e.target == this){
            back.fadeOut(300);
        }
    })
}
